package ru.papergames.utils.helpers
{
		
	public final class TimeHelper
	{
		
		public static function formatDate(d:Date):String {
			
			function twoDigits(n:Number):String {
				return n < 10 ? '0' + n.toString() : n.toString(); 
			}
			
			return twoDigits(d.getDate()) + '-' + 
					twoDigits(d.getMonth() + 1) + '-' + 
						d.getFullYear() + ' ' +
							twoDigits(d.getHours()) + ':' +  
								twoDigits(d.getMinutes()) + ':' +
									twoDigits(d.getSeconds());  
			
		}
		
		public static function formatDateShort(d:Date):String {
			
			function twoDigits(n:Number):String {
				return n < 10 ? '0' + n.toString() : n.toString(); 
			}
			
			return twoDigits(d.getDate()) + '.' + 
				twoDigits(d.getMonth() + 1) + '.' + 
				d.getFullYear();  
			
		}
		
		
		public static function formatTimeShort(d:Date):String {
			
			function twoDigits(n:Number):String {
				return n < 10 ? '0' + n.toString() : n.toString(); 
			}
			
			return twoDigits(d.getHours()) + ':' +  
					twoDigits(d.getMinutes()) + ':' +
						twoDigits(d.getSeconds());  
			
		}
	
		public static function parseDBDate(dbStrDate:String):Date {
			//2009-11-20 13:28:54
			var rezDate:Date = null;
			
			try {
			
				var parts:Array = dbStrDate.split(' ', 2);
				var dateParts:Array = (parts[0] as String).split('-', 3);
				var timeParts:Array = (parts[1] as String).split(':', 3);
				
				rezDate = new Date(dateParts[0], dateParts[1] - 1, dateParts[2],
									timeParts[0], timeParts[1], timeParts[2]);
			
			} catch (e:Error) {
					
					//show error win here
								
			} finally {
				
				return rezDate;
			}
			
			return rezDate;
		}
		
		
		public static function formatSeconds(secs:uint):String {
			var d:Date = new Date();
			d.setHours(0, 0, secs);
			
			return formatTimeShort( d );
		}

	}
}